<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>罗伦士车型配置选择</title>
    <!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> -->
    <!-- 引入 Vue.js -->
    <script src="../../assets/js/vue.js"></script>
    <script src="../../assets/js/auth.js"></script>
    <script src="../../assets/js/constant.js"></script>
    <script src="../../assets/js/utils.js"></script>
    <script src="../../assets/js/axios.min.js"></script>
    <script src="../../assets/js/element-ui.js"></script>
    <style>
        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            line-height: 1.6;
            color: #333;
            max-width: 1000px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        h1 {
            text-align: center;
            color: #2c3e50;
            margin-bottom: 30px;
        }
        .platform-selector {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .platform-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 15px;
            color: #2c3e50;
        }
        .select-group {
            display: flex;
            gap: 20px;
            margin-bottom: 15px;
        }
        .select-wrapper {
            flex: 1;
        }
        select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 15px;
            background-color: #fff;
        }
        select:disabled {
            background-color: #f5f5f5;
            color: #999;
        }
        .fixed-specs {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .specs-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 15px;
            color: #2c3e50;
        }
        .specs-table {
            width: 100%;
            border-collapse: collapse;
        }
        .specs-table th, .specs-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        .specs-table th {
            background-color: #f9f9f9;
            font-weight: bold;
            color: #2c3e50;
        }
        .specs-table tr:hover {
            background-color: #f5f5f5;
        }
        .platform-info {
            margin-top: 10px;
            font-weight: bold;
            color: #2c3e50;
        }
        .main-category {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 30px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            opacity: 0.6;
            transition: opacity 0.3s;
        }
        .main-category.active {
            opacity: 1;
        }
        .main-category-title {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 20px;
            color: #2c3e50;
            border-bottom: 2px solid #eee;
            padding-bottom: 10px;
        }
        .config-section {
            background-color: #f9f9f9;
            border-radius: 6px;
            padding: 15px;
            margin-bottom: 15px;
        }
        .section-title {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 12px;
            color: #2c3e50;
        }
        .option-group {
            margin-bottom: 10px;
        }
        .option-label {
            display: block;
            position: relative;
            padding-left: 35px;
            margin-bottom: 10px;
            cursor: pointer;
            font-size: 15px;
            user-select: none;
        }
        .option-label input {
            position: absolute;
            opacity: 0;
            cursor: pointer;
        }
        .checkmark {
            position: absolute;
            top: 0;
            left: 0;
            height: 20px;
            width: 20px;
            background-color: #eee;
            border-radius: 50%;
        }
        .option-label:hover input ~ .checkmark {
            background-color: #ddd;
        }
        .option-label input:checked ~ .checkmark {
            background-color: #2196F3;
        }
        .checkmark:after {
            content: "";
            position: absolute;
            display: none;
        }
        .option-label input:checked ~ .checkmark:after {
            display: block;
        }
        .option-label .checkmark:after {
            top: 6px;
            left: 6px;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: white;
        }
        .custom-config {
            margin-top: 20px;
        }
        .custom-item {
            display: flex;
            margin-bottom: 10px;
            align-items: center;
        }
        .custom-input {
            flex: 1;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }
        .add-btn {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            margin-left: 10px;
            display: flex;
            align-items: center;
        }
        .add-btn:hover {
            background-color: #45a049;
        }
        .remove-btn {
            background-color: #f44336;
            color: white;
            border: none;
            padding: 8px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            margin-left: 10px;
        }
        .remove-btn:hover {
            background-color: #d32f2f;
        }
        .summary {
            background-color: #2c3e50;
            color: white;
            padding: 20px;
            border-radius: 8px;
            margin-top: 30px;
        }
        .summary-title {
            font-size: 20px;
            margin-bottom: 15px;
            text-align: center;
        }
        .summary-category {
            margin-bottom: 15px;
            padding-bottom: 15px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        }
        .category-title {
            font-weight: bold;
            margin-bottom: 10px;
            font-size: 16px;
        }
        .summary-item {
            margin-bottom: 8px;
            padding-left: 15px;
        }
        .no-selection {
            color: #aaa;
            font-style: italic;
        }
        .custom-summary-item {
            display: flex;
            justify-content: space-between;
        }
        .custom-remove {
            color: #ff9999;
            cursor: pointer;
        }
        /* 添加下单按钮样式 */
        .order-button-container {
            text-align: center;
            margin-top: 30px;
            margin-bottom: 50px;
        }
        .order-button {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 15px 40px;
            border-radius: 8px;
            font-size: 18px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .order-button:hover {
            background-color: #45a049;
        }
        .order-button:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
        }
        .dealer-class {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
            width: 50%;
        }
        .dealer-class span{
            margin-left: 10px;
        }
    </style>
</head>
<body>
    <div id="app">
        <h1>罗伦士车型配置选择</h1>

        <div class="platform-selector">
            <div class="platform-title">经销商信息</div>
            <div class="select-group">
                <div class="dealer-class">
                    <label>经销商:</label>
                    <span>罗伦士张家港店</span>
                    <!--<input v-model="selected.doAmount"/>-->
                </div>
                <div class="dealer-class">
                    <label>门店联系人:</label>
                    <span>王一</span>
                    <!--<input v-model="selected.depositAmount"/>-->
                </div>
            </div>
            <div class="select-group">
                <div class="dealer-class">
                    <label>门店联系方式:</label>
                    <span>15745124587</span>
                    <!--<input v-model="selected.doRate"/>-->
                </div>
                <div class="dealer-class">
                    <label>门店地址:</label>
                    <span >苏州张家港罗伦士园区</span>
                    <!--<input v-model="selected.taxAmount"/>-->
                </div>
            </div>

        </div>

        <!-- 车平台和车型号选择 -->
        <div class="platform-selector">
            <div class="platform-title">选择车平台和车型</div>
            <div class="select-group">
                <div class="select-wrapper">
                    <label for="platform">车平台</label>
                    <select id="platform" v-model="selected.carPlatformCode" @change="getCarModelList()">
                        <option value="">请选择车平台</option>
                        <option v-for="platform in platforms" :value="platform.id">{{ platform.name }}</option>
                    </select>
                </div>
                <div class="select-wrapper">
                    <label for="model">车型号</label>
                    <select id="model" v-model="selected.carModelCode" :disabled="!selected.carPlatformCode" @change="getCarModelConfigList">
                        <option value="">请选择车型号</option>
                        <option v-for="model in filteredModels" :value="model.id">{{ model.name }}</option>
                    </select>
                </div>
            </div>
        </div>

        <!--<div>
            <div v-for="configItem in configOptions" :key="bigConfigCode">
                <div class="main-category-title">{{configItem.bigConfigName}}</div>
                <div class="config-section" v-for="itemSmallConfig in configItem.smallConfigList" :key="smallConfigCode">
                    <div class="section-title">{{itemSmallConfig.smallConfigName}}</div>
                    <div class="option-group">
                        <label class="option-label" v-for="option in itemSmallConfig.optionList" :key="option.optionCode"
                               v-if="itemSmallConfig.configType==='2'" disabled="itemSmallConfig.editFlag==='1'">
                            {{ option.optionName }}
                            <input type="radio" name="grille" v-model="itemSmallConfig.optionValue" :value="option.optionCode">
                            <span class="checkmark"></span>
                        </label>
                        <label class="option-label" v-for="option in itemSmallConfig.optionList" :key="option.optionCode"
                               v-if="itemSmallConfig.configType==='1'" disabled="itemSmallConfig.editFlag==='1'">
                            {{ option.optionName }}
                            <input type="checkbox" v-model="itemSmallConfig.selectedValues" :value="option.optionCode">
                            <span class="checkmark"></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>-->

        <!-- 添加下单按钮 -->
        <div class="order-button-container">
            <button class="order-button" @click="handleOrder" :disabled="!selected.carModelCode">
                确定
            </button>
        </div>
    </div>

    <script>
        checkAuthentication(2)
        new Vue({
            el: '#app',
            data: {
                selected: {
                    carPlatformCode: '',
                    carModelCode: '',
                },
                request_host: request_host,
                customConfigs: [],
                configOptions: [],
                selectValues: [],
                platforms: [],
                filteredModels: [],
                isConfigActive: true
            },
            created() {
                this.getCarPlatformList()
            },
            methods: {
                getCarPlatformList(){
                    try {
                        axios.get(`${this.request_host}/system/platform/allList`).then((response) => {
                            if (response.status == 200) {
                                //this.platforms = response.data.data
                                response.data.data.forEach(element => {
                                    let platformRecord = {
                                        id: element.carPlatformCode,
                                        name: element.carPlatformName
                                    }
                                    this.platforms.push(platformRecord)
                                });
                            }
                        })
                    } catch (error) {
                        console.error('请求失败:', error)
                    }
                },
                getCarModelList(){
                    let queryParam = {
                        carPlatformCode: this.selected.carPlatformCode
                    }
                    try {
                        axios.get(`${this.request_host}/system/model/allList`,{ params: queryParam }).then((response) => {
                            if (response.status == 200) {
                                response.data.data.forEach(element => {
                                    let platModelRecord = {
                                        id: element.carModelCode,
                                        platformId: element.carPlatformCode,
                                        name: element.carModelName
                                    }
                                    this.filteredModels.push(platModelRecord)
                                    console.log(this.filteredModels)
                                });
                            }
                        })
                    } catch (error) {
                        console.error('请求失败:', error)
                    }
                },
                getCarModelConfigList(){
                    try {
                        axios.get(`${this.request_host}/system/optionsConfig/getConfigByCarModelCode?carModelCode=`+this.selected.carModelCode).then((response) => {
                            if (response.status == 200) {
                                this.configOptions = response.data.data
                                console.log(this.configOptions)
                            }
                        })
                    } catch (error) {
                        console.error('请求失败:', error)
                    }
                },
                handleOrder() {
                    // 这里添加下单逻辑
                    let orderInfo = {
                        carModelCode: this.selected.carModelCode,
                        carPlatformCode: this.selected.carPlatformCode,
                    }
                    axios.post(`${this.request_host}/system/do/createOrder`, orderInfo)
                        .then(response => {
                            if (response.data.code === 200){
                                this.$message.success("提交成功")
                                const params = `cdoCode=`+response.data.data.cdoCode;
                                const url = `cdo_car_item.html?${params}`;
                                window.open(url, '_blank');
                            }else {
                                this.$message.error(response.data.msg)
                            }

                        })
                }
            }
        });
    </script>
</body>
</html>
